﻿Imports iConverter.Contracts
Imports System.Configuration
Imports System.Drawing


''' <summary>
''' 处理器对象，用于提供对IProcessing抽象实现
''' </summary>
''' <remarks></remarks>
Public MustInherit Class Processor(Of TSettings As ApplicationSettingsBase)
    Implements IProcessing, IProcessingMetadata



    ''' <summary>
    ''' 创建新的实例
    ''' </summary>
    ''' <param name="id">ID</param>
    ''' <param name="name">名称</param>
    ''' <param name="description">描述</param>
    ''' <param name="lIcon">大图标（32 X 32）</param>
    ''' <param name="sIcon">小图标（16 x 16）</param>
    ''' <remarks></remarks>
    Sub New(ByVal id As Guid,
            ByVal name As String,
            ByVal description As String,
            ByVal lIcon As Bitmap,
            ByVal sIcon As Bitmap)



        Me._id = id
        Me._name = name
        Me._description = description
        Me._icon = lIcon
        Me._smallIcon = sIcon


    End Sub


#Region "插件设置关联"

    ''' <summary>
    ''' 获取或设置插件提供器的实例
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Protected Friend Property Provider As PluginProvider(Of TSettings)


    ''' <summary>
    ''' 获取插件设置的对象
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks>
    ''' 注:如果插件不需要配置，则会返回Nothing
    ''' </remarks>
    Protected ReadOnly Property Settings As TSettings
        Get
            Return If(Me.Provider IsNot Nothing, Me.Provider.Settings, Nothing)
        End Get
    End Property


#End Region



#Region "IProcessing  实现"

    ''' <summary>
    ''' 对 转换文档（IConvertDocument） 进行处理
    ''' </summary>
    ''' <param name="doc">要处理的文档</param>
    ''' <remarks>
    ''' 主程序将通过此调用此方法来对文档进行修改。
    ''' </remarks>
    Public Sub Processing(ByVal doc As Contracts.IConvertDocument) Implements Contracts.IProcessing.Processing
        OnProcessing(doc)
    End Sub

    ''' <summary>
    ''' 处理操作
    ''' </summary>
    ''' <param name="doc"></param>
    ''' <remarks></remarks>
    Protected MustOverride Sub OnProcessing(ByVal doc As IConvertDocument)


#End Region


#Region "IProcessingMetadata 实现"
    Dim _id As Guid
    ''' <summary>
    ''' ID 
    ''' </summary>
    ''' <remarks></remarks>
    Public ReadOnly Property ID As System.Guid Implements Contracts.IPluginMetadata.ID
        Get
            Return Me._id
        End Get
    End Property

    Dim _description As String
    ''' <summary>
    ''' 描述
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property Description As String Implements Contracts.IBaseMetadata.Description
        Get
            Return Me._description
        End Get
    End Property


    Dim _name As String
    ''' <summary>
    ''' 名字
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property Name As String Implements Contracts.IBaseMetadata.Name
        Get
            Return Me._name
        End Get
    End Property

    Dim _icon As Bitmap

    ''' <summary>
    ''' 图标
    ''' </summary>
    ''' <value></value>
    ''' <returns>如果没有可用图标则返回Nothing，否则返回图标的Bitmap对象</returns>
    ''' <remarks>大小在32*32内为最佳</remarks>
    Public ReadOnly Property Icon As System.Drawing.Bitmap Implements Contracts.IPluginMetadata.Icon
        Get
            Return Me._icon
        End Get
    End Property

    Dim _smallIcon As Bitmap

    ''' <summary>
    ''' 小图标
    ''' </summary>
    ''' <value></value>
    ''' <returns>如果没有可用图标则返回Nothing，否则返回图标的Bitmap对象</returns>
    ''' <remarks>用于显示在菜单中（16 x 16 )小图标</remarks>
    Public ReadOnly Property SmallIcon As System.Drawing.Bitmap Implements Contracts.IPluginMetadata.SmallIcon
        Get
            Return Me._smallIcon
        End Get
    End Property


#End Region


End Class
